package org.example.aienglishapp.dto.speech.dialoguebook;

import lombok.Getter;
import lombok.Setter;

import java.sql.Blob;
import java.util.Base64;

@Setter
@Getter
public class DialogueBookDTO {

    private Long bookId;
    private String title;
    private String description;
    private String picture; // Base64 编码的图片

    // 构造函数
    public DialogueBookDTO(Long bookId, String title, String description, Blob picture) {
        this.bookId = bookId;
        this.title = title;
        this.description = description;
        if (picture != null) {
            try {
                byte[] bytes = picture.getBytes(1, (int) picture.length());
                this.picture = Base64.getEncoder().encodeToString(bytes);
            } catch (Exception e) {
                e.printStackTrace();
                this.picture = null;
            }
        } else {
            this.picture = null;
        }
    }

    // 无参构造函数，用于反序列化
    public DialogueBookDTO() {}
}